home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / gsprops.h < prev    next >
C/C++ Source or Header  |  1993-05-13  |  4KB  |  141 lines

  1. /* Copyright (C) 1991, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gsprops.h */
  20. /* "Property list" definitions for Ghostscript */
  21.  
  22. /*
  23.  * Several interfaces in Ghostscript use the idea of a "property list",
  24.  * essentially a dictionary with a fixed set of key names and known
  25.  * value types.  A property list is represented by an array of structures
  26.  * with four components:
  27.  *
  28.  *    - The name of the property;
  29.  *
  30.  *    - The type of value provided (or expected);
  31.  *
  32.  *    - The value itself;
  33.  *
  34.  *    - An indication of whether the value was supplied, and if so,
  35.  * whether it was acceptable.
  36.  *
  37.  * Currently, property lists are only used to communicate parameter values
  38.  * to devices.
  39.  */
  40.  
  41. /* Define the types of values. */
  42. typedef enum {
  43.     prt_int,            /* (long) */
  44.     prt_float,
  45.     prt_bool,
  46.     prt_string,
  47.     prt_int_array,            /* array of prt_int item */
  48.     prt_float_array,        /* array of prt_float item */
  49.     prt_null
  50. } gs_prop_type;
  51. typedef int p_bool;
  52. /* Arrays and strings must represent their size explicitly. */
  53. typedef union gs_prop_value_s gs_prop_value;
  54.  
  55. /* Define the type for property list items. */
  56. #ifndef gs_prop_item_DEFINED
  57. #  define gs_prop_item_DEFINED
  58. typedef struct gs_prop_item_s gs_prop_item;
  59. extern const uint gs_prop_item_sizeof;
  60. #endif
  61.  
  62. /* Define the union of all possible value types. */
  63. union gs_prop_value_s {
  64.     long i;
  65.     float f;
  66.     p_bool b;
  67.     struct {
  68.         ushort size;
  69.         union {
  70.             char *s;
  71.             gs_prop_item *v;
  72.         } p;
  73.     } a;
  74. };
  75.  
  76. /* Define the status of an entry in a property list. */
  77. typedef enum {
  78.     pv_unspecified,            /* no value specified */
  79.     pv_set,                /* other explicit value */
  80.         /* Recipients return these codes */
  81.     pv_OK,
  82.     pv_unknown,            /* unknown key */
  83.     pv_typecheck,
  84.     pv_rangecheck,
  85.     pv_limitcheck
  86. } gs_prop_status;
  87.  
  88. /* Finally, define the structure of a property item. */
  89. struct gs_prop_item_s {
  90.     const char *pname;
  91.     int name_size;            /* -1 means use strlen */
  92.     gs_prop_type type;
  93.     gs_prop_status status;
  94.     gs_prop_value value;
  95. };
  96. #define gs_prop_item_s_DEFINED
  97.  
  98. /*
  99.  * It is often convenient to construct a property list template statically,
  100.  * and just copy it and fill in the values.  Here are some macros useful
  101.  * for doing this.  The format is
  102.  *    prop_item xyz_props[] = {
  103.  *        prop_def("name1", prt1),
  104.  *        prop_def("name2", prt2),
  105.  *        ...
  106.  *    };
  107.  * or
  108.  *    typedef struct {
  109.  *        prop_item name1, name2, ...;
  110.  *    xyz_props_struct;
  111.  *    xyz_props_struct xyz_props = {
  112.  *        prop_def("name1", prt1),
  113.  *        prop_def("name2", prt2),
  114.  *        ...
  115.  *    };
  116.  * For slots that form part of an array, use prop_slot instead of prop_def.
  117.  */
  118. #define prop_def(name, type) { name, -1, type, pv_set }
  119. #define prop_int { 0, -1, prt_int, pv_set }
  120. #define prop_float { 0, -1, prt_float, pv_set }
  121.  
  122. /*
  123.  * The recipient of a property list typically wants to extract a set of
  124.  * known properties and disregard the rest.  The following procedure
  125.  * (implemented in gsutil.c) accomplishes this.
  126.  */
  127.  
  128. extern int props_extract(P6(
  129.     struct gs_prop_item_s *plist,    /* plist[count] */
  130.     int count,
  131.     const struct gs_prop_item_s *template, /* template[tcount] */
  132.                     /* (the known properties) */
  133.     int tcount,
  134.     struct gs_prop_item_s **pknown,    /* *pknown[tcount] */
  135.                     /* (these are set to point to the */
  136.                     /* corresponding items in plist, */
  137.                     /* or NULL if the item is absent) */
  138.     int finished            /* if true, mark remaining items */
  139.                     /* in plist as pv_unknown */
  140. ));
  141.